<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
		<title>表单页面</title>
		<link href="../../component/pear/css/pear.css" rel="stylesheet">
	</head>
	<body class="pear-container">
		<div class="layui-row layui-col-space10">

            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">作者及博客基本信息</div>
                    <div class="layui-card-body" style="color: red">
                        此部分信息是存入redis缓存中的，如果缓存数据丢失，会从AuthorInfo类中从新初始化
                    </div>
                </div>
            </div>


            <form class="layui-form" action="javascript:void(0);" lay-filter="example">
                <div class="layui-form-item">

                    <div class="layui-col-md6" style="padding: 5px;">

                        <div class="layui-card">
                            <div class="layui-card-header">名称</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md6">
                                    <input type="text" name="nickname" hover placeholder="用户名" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-card layui-form" lay-filter="component-form-element">
                            <div class="layui-card-header">性别</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <input type="radio" name="sex" value="男" title="男" checked>
                                    <input type="radio" name="sex" value="女" title="女">
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">头像</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <input type="text" name="headPortrait" placeholder="请输入头像" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">座右铭</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="motto" placeholder="请输入座右铭" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">博客简介</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="blogSynopsis" placeholder="请输入博客简介" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>

                    </div>

                    <div class="layui-col-md6" style="padding: 5px;">
                        <div class="layui-card">
                            <div class="layui-card-header">个人简介</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="synopsis" placeholder="请输入个人简介" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">详细个人信息</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="personalInfo" placeholder="请输入个人信息" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">兴趣爱好</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="interests" placeholder="请输入兴趣爱好" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>

                        <div class="layui-card">
                            <div class="layui-card-header">畅想未来</div>
                            <div class="layui-card-body layui-row layui-col-space10">
                                <div class="layui-col-md12">
                                    <textarea name="futurePlans" placeholder="请输入畅想未来" class="layui-textarea"></textarea>
                                </div>
                            </div>
                        </div>
                    </div>

                </div>


                <div class="layui-form-item" style="text-align: center">
                    <div class="layui-col-md12">
                        <button id="user-save" type="button" class="pear-btn pear-btn-success login permission" permission = 'authorInfo:update' lay-submit
                                lay-filter="login">
                            保 存
                        </button>
                    </div>
                </div>

            </form>


		</div>
		<script src="../../component/layui/layui.js"></script>
		<script src="../../component/pear/pear.js"></script>
        <script src="../../js/baseUrl.js"></script>
        <script src="../../js/cookieUtils.js"></script>
        <script src="../../component/pear/module/ajaxRequest.js"></script>
        <script src="../../js/jquery-3.2.1.min.js"></script>
        <script src="../../js/permission.js"></script>
		<script>
			layui.use(['form','element','code','ajaxRequest','jquery','toast'], function() {
				var form = layui.form;
				var element = layui.element;
				var ajaxRequest = layui.ajaxRequest;
				var $ = layui.jquery;
				var toast = layui.toast;

				$(function () {
				    // 加载基本信息
                    var result = ajaxRequest.sendGet("/admin/cache/getAuthorInfo",{},false,true);
                    if (result){
                        form.val('example', result.data);
                    }

                    // 添加权限验证
                    validaPermission();
                });

                form.on('submit(login)', function(data) {
                    let formDate = data.field;
                    var result = ajaxRequest.sendGet("/admin/cache/updateAuthorInfo",formDate,false,true);
                    // 结果处理
                    if (result) {
                        toast.success({title: 'Success',message: result.msg,position: 'topRight'});
                    }
                    return false;
                });

			});
		</script>
	</body>
</html>
